package net.pws.common.simplemq;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class MessageSender implements Action {
    
    private static final Log logger = LogFactory.getLog(MessageSender.class);
    
    private Action action;
    
    public MessageSender(Action action) {
        super();
        this.action = action;
    }
    
    public void execute(Context context) {
        logger.debug("MessageSender start...");
        try {
            action.execute(context);
        }
        catch (Exception e) {
            logger.error("Message send failed!The reason is " + e.getMessage(),
                         e);
            context.getQueue().addLazyData(context.getData(), 60 * 10);
        }
        finally {
            logger.debug("MessageSender end!");
        }
    }
    
}
